package com.tianyi.sfzy1.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tianyi.sfzy1.domain.Featuredarticle;
import com.tianyi.sfzy1.mapper.FeaturedarticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FeaturedarticleService {
    @Autowired
    private FeaturedarticleMapper featuredarticleMapper;

    //查询所有
    public List<Featuredarticle> findAll(){
        return featuredarticleMapper.findAll();
    }

    //根据id查询
    public Featuredarticle selectByPrimaryKey(int articleId){
        return featuredarticleMapper.selectByPrimaryKey(articleId);
    }

    //模糊查询
//    List<Featuredarticle> findByTitle(String title){
//        return featuredarticleMapper.findByTitle(title);
//    }

    //分页查询
    public PageInfo<Featuredarticle> findByPage(int pageNum, int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Featuredarticle> featuredarticlesList = featuredarticleMapper.findAll();
        //查询操作之后，封装分页数据
PageInfo<Featuredarticle> pageInfo = new PageInfo<>(featuredarticlesList);
return pageInfo;
    }
//    public List<Featuredarticle> findByPage(int start, int pageSize){
//        return featuredarticleMapper.findByPage();
//    }



//    //修改
    public int updateByPrimaryKey(Featuredarticle featuredarticle){
        return featuredarticleMapper.updateByPrimaryKey(featuredarticle);
    }
    //删除
    public int deleteByPrimaryKey(int articleId){
        return featuredarticleMapper.deleteByPrimaryKey(articleId);
    }

    //根据咨询师id查询文章
    public List<Featuredarticle> findByConsultantId(int consultantId){
        return featuredarticleMapper.findByConsultantId(consultantId);
    }


    //   课程收藏表 和 咨询师表查询
    public List<Featuredarticle> findCourseFavoriteAndConsultant(){
        return featuredarticleMapper.findCourseFavoriteAndConsultant();
    }
    //新增
    public int insert(Featuredarticle record){
        return featuredarticleMapper.insert(record);
    }

    //富文本编辑器上传
//    public int insertFeaturedarticle(Featuredarticle featuredarticle){
//        return featuredarticleMapper.insertFeaturedarticle(featuredarticle);
//    }

    public Featuredarticle findArticlebyId(int articleId){
        return featuredarticleMapper.findArticlebyId(articleId);
    }
}
